<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="queryForm" :model="listQuery" :inline="true" class="form-inline">
        <el-form-item label="任务名称" prop="jobName">
          <el-select v-model="listQuery.executeJobId" class="filter-item" placeholder="请选择任务">
            <el-option v-for="(item, index) in fastlist" :key="index" :label="item.jobName" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="listQuery.status" clearable placeholder="请选择状态" style="width: 200px">
            <el-option v-for="item in dictList('execute_status')" :key="'type' + item.label" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
          {{ $t('table.search') }}
        </el-button>
        <el-button v-waves class="filter-item" icon="el-icon-refresh" @click="handleRest">
          {{ $t('table.rest') }}
        </el-button>
      </el-form>
    </div>

    <el-table ref="table" :key="tableKey" v-loading="listLoading" element-loading-text="正在加载，请稍后" :data="list" border fit highlight-current-row style="width: 100%">
      <el-table-column type="index" align="center" width="100" label="序号" />
      <el-table-column label="执行任务名称" align="center" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.jobName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.status | dictLabel('execute_status') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="执行时间" align="center" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.executeDate }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" fixed="right" align="center" min-width="150" class-name="small-padding fixed-width">
        <template slot-scope="{ row }">
          <el-button v-permission="['datagovernance:DataGovernanceTaskLog:update']" type="text" size="small" icon="el-icon-edit" @click="handleUpdate(row)">
            {{ $t('table.checklog') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" :page-sizes="pageArray" @pagination="getList" />

    <data-extraction-task-log-form ref="form" @refreshList="getList" />
  </div>
</template>

<script>
import { deleteDataExtractionTaskLog, fetchDataExtractionTaskLogList } from '@/api/dataextractiontasklog/dataExtractionTaskLog'
import { fetchDataExtractionTaskList } from '@/api/dataextractiontask/dataExtractionTask'
import waves from '@/directive/waves' // waves directive
import permission from '@/directive/permission/permission'
import dataExtractionTaskLogForm from './dataExtractionTaskLogForm'
import Pagination from '@/components/Pagination'

export default {
  name: 'DataExtractionTaskLogList',
  components: { dataExtractionTaskLogForm, Pagination },
  directives: { waves, permission },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      pageArray: this.$store.getters.pageArray,
      listQuery: {
        jobName: '',
        page: 1,
        limit: this.$store.getters.defaultPageSize,
      },
      passobj: {
        taskId: '',
        page: 1,
        limit: 999,
      },
      fastlist: [],
    }
  },
  created() {
    fetchDataExtractionTaskList(this.passobj).then((response) => {
      if (response.data.code == 0) {
        this.fastlist = response.data.data
        this.listLoading = false
      } else {
        this.$message.error(response.data.msg)
      }
    })
    this.getList()
  },
  methods: {
    handleRest() {
      this.listQuery.executeJobId = ''
      this.getList()
    },
    getList() {
      this.listLoading = true
      fetchDataExtractionTaskLogList(this.listQuery).then((response) => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },
    handleCreate() {
      this.$refs.form.handleCreate()
    },
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row.id)
    },
    handleDelete(row) {
      this.$confirm('确定删除该数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        deleteDataExtractionTaskLog(row.id).then((response) => {
          if (response.data.code === 0) {
            this.getList()
            this.$message.success(response.data.msg)
          } else {
            this.$message.error(response.data.msg)
          }
        })
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
  },
}
</script>
<style lang="scss" scoped>
::v-deep(::-webkit-scrollbar) {
  display: block !important;
}
</style>
